﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using HoneyBadgersOfficePlayer.Models;

namespace HoneyBadgersOfficePlayer.Views
{
    public partial class Library : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                List<SqlParameter> parameterList = new List<SqlParameter>();
                parameterList.Add(new SqlParameter("@User_ID", Globals.UserID));
                SqlDataReader reader = SQLUtilities.RunStoredProcedure("Get_Users_Average_Song_rating", parameterList);

                if (reader != null)
                {
                    ////shellies code
                    DataTable dt = new DataTable();
                    ////jestins code
                    BoundField bf = new BoundField();
                    BoundField bf1 = new BoundField();

                    ////shellies code
                    dt.Columns.Add("Song");
                    dt.Columns.Add("Rating");

                    while (reader.Read())
                    {

                        ////shellies code
                        string rating = reader[0].ToString();
                        string song = reader[1].ToString();

                        //dt.Rows.Add(rating, artist, song, genre, songID);
                        dt.Rows.Add(
                        bf1.DataField.Insert(0, rating),
                        bf.DataField.Insert(0, song)
                        );

                    }
                    Session["CACHEDATA1"] = dt;
                    GridView2.DataSource = dt;
                    GridView2.DataBind();
                }

                parameterList.Clear();
                parameterList = new List<SqlParameter>();
                parameterList.Add(new SqlParameter("@User_ID", Globals.UserID));
                SqlDataReader reader2 = SQLUtilities.RunStoredProcedure("Get_Users_Song_rating", parameterList);

                if (reader2 != null)
                {
                    ////shellies code
                    DataTable dt = new DataTable();
                    ////jestins code
                    BoundField bf = new BoundField();
                    BoundField bf1 = new BoundField();
                    BoundField bf2 = new BoundField();

                    ////shellies code
                    dt.Columns.Add("Song");
                    dt.Columns.Add("User");
                    dt.Columns.Add("Ratings");

                    while (reader2.Read())
                    {

                        ////shellies code
                        string song = reader2[0].ToString();
                        string user = reader2[1].ToString();
                        string rating = reader2[2].ToString();

                        //dt.Rows.Add(rating, artist, song, genre, songID);
                        dt.Rows.Add(
                        bf1.DataField.Insert(0, song),
                        bf.DataField.Insert(0, user),
                        bf2.DataField.Insert(0, rating)
                        );

                    }
                    Session["CACHEDATA1"] = dt;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }
    }
}